#ifndef _DATAGRAM_HPP_20120414
#define _DATAGRAM_HPP_20120414

#include "base.hpp"
#include "idatagram.hpp"

namespace datagram
{
	struct Datagram
	{
		public :
#define DATAGRAM_DEF_TYPE(class, name, value) \
			name = value,

			enum
			{
#include "datagram_def_type.i"
			};

#undef DATAGRAM_DEF_TYPE

			static const char * type_string(uint32_t type)
			{
#define DATAGRAM_DEF_TYPE(class, name, value) \
				case name: \
				{ \
					return #name; \
				}

				switch (type)
				{
#include "datagram_def_type.i"
					default:
						return "T_UNKNOW";
				}
			}
#undef DATAGRAM_DEF_TYPE
	};

	struct DatagramTest1Req : public IDatagram
	{
		public :
			DatagramTest1Req()
				: IDatagram(Datagram::T_DATAGRAM_TEST1_REQ)
			{
			}

			virtual void serialize(Streamer & streamer)
			{
				IDatagram::serialize(streamer);
				streamer & _data;
			}

			virtual std::string to_string() const
			{
				std::ostringstream oss;

				oss << "{head: " << IDatagram::to_string()
					<< ", data: " << _data
					<< "}";

				return oss.str();
			}

		public :
			std::string   _data;
	};

	struct DatagramTest1Resp : public IDatagram
	{
		public :
			DatagramTest1Resp()
				: IDatagram(Datagram::T_DATAGRAM_TEST1_RESP)
			{
			}

			virtual void serialize(Streamer & streamer)
			{
				IDatagram::serialize(streamer);
				streamer & _times
					     & _data;
			}

			virtual std::string to_string() const
			{
				std::ostringstream oss;

				oss << "{head: " << IDatagram::to_string()
					<< ", times: " << _times
					<< ", data: " << _data
					<< "}";

				return oss.str();
			}

		public :
			uint32_t     _times;
			std::string  _data;
	};
};

#endif

